package mh.entity.object.attributes;

import mh.entity.Entity;
import mh.entity.object.EntityObject;

public abstract class ObjectAttribute {
	/**
	 * Reference to the object that has this attribute
	 */
	protected EntityObject	obj;

	public ObjectAttribute(EntityObject o) {
		this.obj = o;
	}

	public abstract boolean isValid(Entity interact);

	@Override
	public abstract boolean equals(Object o);

	/**
	 * Returns the direction of the interaction -1 = error 0 = over 1 = top 2 = top-right 3 = right 4 = right-bottom 5 =
	 * bottom 6 = bottom-left 7 = left 8 = left-top
	 * 
	 * @param x
	 * @param y
	 * @param interactionX
	 * @param interactionY
	 * @return
	 */
	public static int getInteractionDirection(int x, int y, int interactionX, int interactionY) {
		if ((y == interactionY) && (x == interactionX)) { //over
			return 0;
		}
		if ((x == interactionX) && (y >= interactionY)) { //top
			return 1;
		}
		if ((x <= interactionX) && (y >= interactionY)) { //top-right
			return 2;
		}
		if ((x <= interactionX) && (y == interactionY)) { //right
			return 3;
		}
		if ((x <= interactionX) && (y <= interactionY)) { //right-bottom
			return 4;
		}
		if ((x == interactionX) && (y <= interactionY)) { //bottom
			return 5;
		}
		if ((x >= interactionX) && (y <= interactionY)) { //bottom-left
			return 6;
		}
		if ((x >= interactionX) && (y == interactionY)) { //left
			return 7;
		}
		if ((x >= interactionX) && (y >= interactionY)) { //left
			return 8;
		}

		return -1;
	}
}
